package com.vnp.cooking.UIcontrols;

import com.vnp.cooking.ApplicationContext;

import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.widget.Toast;

public class GestureListener extends SimpleOnGestureListener {
	private static final int SWIPE_MIN_DISTANCE = 150;
	private static final int SWIPE_MAX_OFF_PATH = 100;
	private static final int SWIPE_THRESHOLD_VELOCITY = 100;

	private MotionEvent mLastOnDownEvent = null;

	@Override
	public boolean onDown(MotionEvent e) {
		mLastOnDownEvent = e;
		return super.onDown(e);
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		if (e1 == null) {
			e1 = mLastOnDownEvent;
		}
		if (e1 == null || e2 == null) {
			return false;
		}

		float dX = e2.getX() - e1.getX();
		float dY = e1.getY() - e2.getY();

		if (Math.abs(dY) < SWIPE_MAX_OFF_PATH
				&& Math.abs(velocityX) >= SWIPE_THRESHOLD_VELOCITY
				&& Math.abs(dX) >= SWIPE_MIN_DISTANCE) {
			if (dX > 0) {
				Toast.makeText(ApplicationContext.getContext(), "Right Swipe",
						Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(ApplicationContext.getContext(), "Left Swipe",
						Toast.LENGTH_SHORT).show();
			}
			return true;
		} else if (Math.abs(dX) < SWIPE_MAX_OFF_PATH
				&& Math.abs(velocityY) >= SWIPE_THRESHOLD_VELOCITY
				&& Math.abs(dY) >= SWIPE_MIN_DISTANCE) {
			if (dY > 0) {
				Toast.makeText(ApplicationContext.getContext(), "Up Swipe",
						Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(ApplicationContext.getContext(), "Down Swipe",
						Toast.LENGTH_SHORT).show();
			}
			return true;
		}
		return false;
	}
	
	
}